<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 1.引入vue.js文件 -->
    <script src="js/vue.js"></script>
    <style>
        .father {
            width: 300px;
            height: 300px;
            border: 2px solid red;
        }
        
        .son {
            width: 150px;
            height: 150px;
            background-color: blue;
        }
        
        .grandfather {
            width: 400px;
            height: 400px;
            border: 3px solid yellow;
        }
    </style>
</head>

<body>
    <!-- 声明式渲染 -->
    <div id="app">
        <div class="father" @click="faFun">父元素
            <!-- .stop:阻止事件传播 -->
            <div class="son" @click.stop="sonFun">子元素</div>
        </div>
        <!-- .prevent:阻止默认事件 -->
        <a href="http://www.baidu.com" @click.prevent="aFun">走起</a>

        <!-- .stop.prevent 链式使用 -->
        <div class="father" @click="faFun">
            <a href="http://www.baidu.com" @click.stop.prevent="aFun">点击a元素</a>
        </div>
        <button class="onceBtn" @click.once="onceFun">只触发一次</button>

        <h2>事件捕获</h2>
        <!-- .capture -->
        <div class="grandfather" @click.capture="grFun">爷爷元素
            <div class="father" @click.capture="faFun">父元素
                <div class="son" @click.capture="sonFun">子元素</div>
            </div>
        </div>
        <h2>触发自己范围事件</h2>
        <!-- .self -->
        <div class="grandfather" @click="grFun">爷爷元素
            <div class="father" @click.self="faFun">父元素
                <div class="son" @click="sonFun">子元素</div>
            </div>
        </div>

    </div>
    <!-- {{msg}} -->
    <script>
        var app = new Vue({
            // element
            // 挂载元素
            el: '#app',
            // 渲染数据定义
            data: {
                num: 10
            },
            methods: {
                faFun() {
                    console.log('父元素');
                },
                sonFun() {
                    console.log('子元素');
                },
                aFun() {
                    console.log('点击a元素');
                },
                onceFun() {
                    console.log('点击了');
                },
                grFun() {
                    console.log('爷爷元素');
                }
            }
        });
    </script>
</body>

</html>